package com.arnold.guide.sparkSql.demo03

import org.apache.spark.sql.SparkSession

/**
  * Created by arnold.zhu on 2017/7/24.
  */
object Demo03 {

  private val sparkSession: SparkSession = SparkSession.builder().master("local").appName("LearnSparkSQL").getOrCreate()

  def main(args: Array[String]): Unit = {
    val path: String = Thread.currentThread().getContextClassLoader.getResource("sparksql/demo01/people.json").getPath

    val df = sparkSession.read.json(path)

    import sparkSession.implicits._

    // 过滤年龄大于21的数据 并创建一个临时视图 tempView
    df.filter($"age" > 21).createOrReplaceTempView("tempView")

    sparkSession.sql("select * from tempView").show()
  }

}
